#
# $Id: kshrc,v 1.1.1.1 2010/11/06 11:12:37 pgurumur Exp $
# Copyright (c) 2009 Prabhu Gurumurthy <pgurumur@gmail.com>
# 
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# 
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#       
arch=`uname -m`
export CVSROOT=:ext:`whoami`@cvs.kashyapa.net:/repos/cvs
export CVS_RSH=ssh
export EDITOR=vi
export HISTFILE=${HOME}/.ksh_history
export HISTSIZE=1000
export LESS="-P?fFile\: %f ?lLines\:%l\/%L %p\% Page\:%d Size\:%s\B"
export LANG="C"
export MANPAGER=less
export PAGER=less
export PKG_PATH="ftp://ftp.openbsd.org/pub/OpenBSD/snapshots/packages/${arch}/"
export RCS_EDITOR=vim
export SUDO_PROMPT="[sudo] %u password on %h: "
export TEMP=/tmp
export TZ=PST8PDT
export WWW_HOME=http://www.openbsd.org

if [ ${TERM} = "screen" ]; then
	export TERM=xterm-color
fi

export TERM=xterm
SYSTEM=`hostname -s`
export SCREENRC=${HOME}/.screenrc.${SYSTEM}

TITLEBAR='\[]0;\u@\h (\l): \W\]'
MACHINE=`uname -s`
PROMPT="$ "
PS1=
PS2=
PS4=

if [ ${TERM} = "xterm" ]; then
	PS1="${TITLEBAR}\h: [\w]\n[\!]${PROMPT}"
	PS2="${TITLEBAR}[\w]${PROMPT}"
else
	PS1="\h: [\w]\n[\!]${PROMPT}"
	PS2="[\w]${PROMPT}"
fi

PS4="[\w]+ "

export PS1 PS2 PS4

function se {
   export VISUAL=${EDITOR}
   export EDITOR=vim
   sudoedit $*
   export EDITOR=${VISUAL}
   export VISUAL=
}

function ldlist {
   if [ -n "$1" ]; then
      readelf -ds `which $1` | fgrep NEEDED
   fi
}

function listproc {
   echo -n "List of processes: "
   ps ux | sed -e '1d' | sed -n '$='
}

function show {
   prog="show"
   awk=`which awk`
   arp=`which arp`
   netstat=`which netstat`
   ndp=`which ndp`

   case "$1" in
      ip)
         param=$2
         if [ ! -z ${param} ]; then
            if [ ${param} = "route" ]; then
               ${netstat} -rnf inet
            else
               echo "${prog} ip route"
            fi
         else
            echo "${prog} ip route"
         fi
         ;;

      ipsec)
         param=$2
         if [ ! -z ${param} ]; then
            if [ ${param} = "route" ]; then
               ${netstat} -rnf encap
            else
               echo "${prog} ipsec route"
            fi
         else
            echo "${prog} ipsec route"
         fi
         ;;

      arp)
         ${arp} -an | \
            ${awk} '{ gsub(/\(|\)/, "", $2);
               if (!($4 ~ /incomplete/)) { printf("%s %s %s\n", $NF, $2, $4); }
            }'
         ;;

      path)
         echo "PATH: "
         echo ${PATH} | awk '{ 
         split($0, ip, /:/); 
         for (ix = 1; ix <= length(ip); ix ++)
            { printf("\t%s\n", ip[ix]); } 
         }'
         ;;

      ?)
         echo "   [ ip | ipsec | arp ]"
         ;;

      *)
         echo "${prog} options"
         echo "options: "
         echo "\t [ ip | ipsec | arp | path ]"
         ;;
   esac
}
         
	
alias ls='ls -Fh'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias s='sudo'
alias sc='ssh-agent /usr/local/bin/screen'
alias rehash='. ${HOME}/.kshrc'

set -o emacs
set -o gmacs
set -o noclobber
set -o posix
set -o ignoreeof
set -o csh-history
set -o braceexpand

bind -m ='clear'
